<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        window.onload{
        var div=document.querySelector('div');
        function times(){
            var timer=+new Date('2021-10-06 15:15:09');
            var nowtimes=+new Date();
            var seconds=(timer-nowtimes)/1000;//获得剩下的秒
            var d = parseInt(seconds / 3600 / 24);//得到天数
            var h = parseInt(seconds / 3600 % 24);//小时
            var m = parseInt(seconds / 60 % 60);//分钟
            var s = parseInt(seconds % 60);//秒
            return div.innerHTML= d+'天'+h+'小时'+m+'分钟'+s+'秒';
        }
        // console.log(times());
        times();
        setInterval(times,1000);
        }
    </script>
    <div></div>
    
</body>
</html>